#ifndef LEDHD44780_H_

#include "LED.h"

#define LEDHD44780_H_

#define MaxDisplayAddress	0x50
#define MaxSGRAMAddress		0x40

#define LEDDisplaySettings	0x08
#define LEDBitDisplay		0x02
#define LEDBITCursor		0x01
#define LEDBITCursorFlash	0x00

#define LEDBusSettings		0x20
#define LEDBitBusWidth		0x04
#define LEDBitBusLenesCount	0x03
#define LEDBitPixels		0x02

#define LEDZeroPosition		0x02
#define LEDDisplayClear		0x00

#define LEDScreenCursorScroll		0x04
#define LEDBitCursorPosInc			0x01
#define LEDBitScreenScroll			0x00

#define LEDScreenCursorMove			0x10
#define LEDBitScrCursMove			0x03
#define LEDBitScrCursMoveDirection	0x02

#define LEDDisplayAddress	0x80
#define LEDSGRAMAddress		0x40

#define LEDLineMaxCount				2
#define LEDLineLenght				64//28
#define LEDRowVisibleMaxCount		16

enum eBusWidth		{Bus4Pin, Bus8Pin};
enum eLinesCount	{Lines1, Lines2};
enum ePixels		{Pixel2x8, Pixel2x10};
enum eScrCurs		{Cursor, Screen};
enum eMoveDirection	{Left, Right};
enum eDataOrCommand	{DataStrobe, CommandStrobe};

class clLEDHD44780: public clLEDDriver{
	public:
		clLEDHD44780(PortStruct lPortData, PortStruct lPortCommand, ePins lPinStrobe, ePins lPinCommand,
			bool UseHighPinsData, eBusWidth lBusWidth, ePixels lPixels);
		void DisplayClear(void);
		void DisplayOn(bool lVal);
		void CursorShow(bool lVal);
		void CursorFlash(bool lVal);
		void GoToZeroPosition(void);
		void CursorShiftRightState(bool lVall);
		void ScreenShiftState(bool lVal);
		void CursorLeft(void);
		void CursorRight(void);
		void ScreenLeft(void);
		void ScreenRight(void);
		bool SetDisplayAddress(unsigned char);
		bool SetSGRAMAddress(unsigned char);
		void PrintChar(unsigned char lVal);
		void Print(const char *String);
		bool SetXYPosition(int X, int Y);
		unsigned char LinesCount;
		unsigned char RowsCount;
	private:
		eBusWidth	BusWidth;
		ePixels		Pixels;
		bool		DisplayStatus;
		bool		CursorStatus;
		bool		CursorFlashStatus;
		PortStruct	PortData;
		PortStruct	PortCommand;
		ePins		PinStrobe;
		ePins		PinCommand;
		unsigned char	UseDataPins;
		bool		CursorShiftRight;
		bool		ScreenShift;
		void SendData4HighBit(unsigned char lByte, bool Command);
		void SendData(unsigned char lByte, bool Command);
		void _SendData(unsigned char lByte, bool Command, bool Only4HighBit);
		void Strobe(void);
		void SetCommandPin(void);
		void DropCommandPin(void);
		void SetCommandMode(void);
		void SetDataMode(void);
		void SetDataPins(unsigned char lByte);
		void SetupMCDDRRegs(void);
		void UpdateDisplaySettings(void);
		void UpdateCursorScreenShift(void);
		unsigned char ConvertASCIICharToLEDChar(unsigned char ASCIIChar);
};


#include "LEDHD44780.cpp"

#endif